#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 505;
const int MOD = 998244353;

int n, m, c[N];
char str[N];
ll fastpow(ll b, ll p) {
  ll res = 1;
  while (p) {
    if (p & 1) res = res * b % MOD;
    b = b * b % MOD;
    p >>= 1;
  }
  return res;
}
bool check() {
  int cnt0 = 0;
  rep(i, 1, n) if (str[i] == '0') cnt0++;
  return !cnt0;
}
void solve_mn() {
  if (!check())
    cout << 0;
  else
    cout << fastpow(2, n);
}
void solve_all() { cout << fastpow(2, n); }
void solve_18() {
  int mx = 1 << n;
  vector<vector<int>> dp(mx, vector<int>(n + 1, 0));
  dp[0][0] = 1;
  rep(s, 1, mx - 1) {
    int x = __builtin_popcount(s);
    rep(i, 1, n) {
      if ((s >> (i - 1)) & 1) {
        int s0 = s ^ (1 << (i - 1));
        rep(j, 0, x - 1) {
          int k = j + (str[x] == '0' || c[i] <= j ? 1 : 0);
          dp[s][k] = (dp[s][k] + dp[s0][j]) % MOD;
        }
      }
    }
  }
  ll res = 0;
  rep(i, 0, n - m) res = (res + dp[mx - 1][i]) % MOD;
  cout << res;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> str[i];
  rep(i, 1, n) cin >> c[i];
  if (m == n)
    solve_mn();
  else if (n <= 18)
    solve_18();
  else if (check())
    solve_all();
  else
    cout << 0;
  return 0;
}